# Create your views here.
from blog import access
from blog.models import Author, Blog, Category, Entry
from django.http import HttpResponse
from django.shortcuts import render_to_response
from google.appengine.api import users

@access('public', None)
def index(request):
  blog = Blog.get()
  if not blog: return render_to_response('blog/coming_soon.html')
  entries = blog.get_published_entries()
  params = {
    'blog': blog,
    'entries': entries,
  }
  return render_to_response('blog/entry_list.html', params)

#@access('logged_in', users.create_login_url('/'))
@access('public', None)
def entry(request, entry_id):
  blog = Blog.get()
  if not blog: return render_to_response('blog/coming_soon.html')
  entry = Entry.get_by_id(int(entry_id))
  params = {
    'blog': blog,
    'entry': entry,
  }
  return render_to_response('blog/entry.html', params)

@access('public', None)
def category(request, category_id):
  blog = Blog.get()
  if not blog: return render_to_response('blog/coming_soon.html')
  category = Category.get_by_id(int(category_id))
  entries = category.entries
  params = {
    'blog': blog,
    'entries': entries,
  }
  return render_to_response('blog/entry_list.html', params)
